#!/bin/bash

# Get PIDs of processes containing main.py
pids=$(pgrep -f main.py)

# If PIDs are found, kill them
if [ -n "$pids" ]; then
    echo "Killing processes: $pids"
    kill $pids

    # Wait for processes to terminate
    for pid in $pids; do
        while kill -0 $pid 2>/dev/null; do
            sleep 1
        done
        echo "Process $pid has been terminated."
    done
else
    echo "No processes containing main.py found."
fi

# Remove app.log if it exists
if [ -f "app.log" ]; then
    rm -f app.log
    echo "app.log has been deleted."
else
    echo "app.log does not exist."
fi

# Remove nohup_main.out if it exists
if [ -f "nohup_main.out" ]; then
    rm -f nohup_main.out
    echo "nohup_main.out has been deleted."
else
    echo "nohup_main.out does not exist."
fi


# Remove nohup.out if it exists
if [ -f "nohup.out" ]; then
    rm -f nohup.out
    echo "nohup.out has been deleted."
else
    echo "nohup.out does not exist."
fi